package com.wave12.pro_cart.controller;

import com.github.pagehelper.PageInfo;
import com.wave12.pro_cart.entity.ProCart;
import com.wave12.pro_cart.pub.ErrorCode;
import com.wave12.pro_cart.service.ProCartService;
import com.wave12.utility.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @Auther: blackcat
 * @Date: 2021-06-08
 * @Description: com.wave12.pro_cart.controller
 * @version:
 */
@Controller
@RequestMapping(value = "/unCart")
public class ProCartController {
    
    private static final Logger logger = LoggerFactory.getLogger(CartController.class);
    @Autowired
    private ProCartService proCartService;
    
    /**
     * 获取proCart 分页查询
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value="/getProCartPageList", method = RequestMethod.POST)
    public Result getProCartList(HttpServletRequest request,@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "2") Integer size,@RequestParam(defaultValue = "1") Integer type){
        PageInfo<ProCart> proCartList = proCartService.getProCartList(page,size, type);
        if (proCartList.getSize()==0)
            return Result.fail(ErrorCode.SELECT_MISS_ERROR.code(),"");
        return Result.succeed(0, "查询成功", proCartList);
    }
    
    /**
     * 根据userId获取产品信息
     * @param request
     * @param userId
     * @return
     */
    @ResponseBody
    @RequestMapping(value="/getProjectDetail", method = RequestMethod.POST)
    public Result getProjectDetail(HttpServletRequest request,String userId,String id){
        ProCart proCart = proCartService.getProjectDetail(userId,id);
        
        return Result.succeed(0, "查询成功", proCart);
    }

}
